package plugins.detail;

import kd.bos.form.events.SetFilterEvent;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.sdk.plugin.Plugin;

import java.util.EventObject;

/**
 * 标准单据列表插件
 */
public class OpenShouCang extends AbstractListPlugin implements Plugin {

    boolean ShouCang = false; // 新增标志位，标记是否打开收藏记录

    @Override
    public void afterCreateNewData(EventObject e) {
        super.afterCreateNewData(e);

        String model = this.getView().getFormShowParameter().getCustomParam("Model");

        if ("shoucang".equals(model)) {
            // 如果Model参数为"shoucang"，则设置标志位为true
            ShouCang = true;

            // 设置按钮可见
            this.getView().setVisible(true, "dcb4_cancelshoucang");
            this.getView().setVisible(true, "dcb4_shoucangrefresh");
            this.getView().setVisible(false, "dcb4_shoucangmerchant");
            this.getView().setVisible(false, "tblrefresh");

        }
    }

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);

        // 如果标志位为true，则设置按钮可见
        if (ShouCang) {
            this.getView().setVisible(true, "dcb4_cancelshoucang");
            this.getView().setVisible(true, "dcb4_shoucangrefresh");
            this.getView().setVisible(false, "dcb4_shoucangmerchant");
        }
    }

    @Override
    public void setFilter(SetFilterEvent e) {
        super.setFilter(e);

        // 如果标志位为true，则添加自定义过滤条件
        if (ShouCang) {
            QFilter filter = new QFilter("dcb4_ifshoucang", QCP.equals, "B");
            e.addCustomQFilter(filter);
        }
    }
}